package com.leyou.user.controller;

import com.leyou.user.dto.InformationDTO;
import com.leyou.user.dto.LoDTO;
import com.leyou.user.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LT
 * @version 1.0.0
 * @ClassName InformationController.java
 * @Description TODO
 * @createTime 2020年05月29日 22:08:00
 */
@RestController
public class InformationController {

    @Autowired
    private InformationService informationService ;

    /**
     * 更新个人信息
     * @param informationDTO
     * @return
     */
    @PostMapping("/update")
    public ResponseEntity<Void> edit(@RequestBody InformationDTO informationDTO){
        informationService.update(informationDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询个人信息
     * @return
     */
    @GetMapping("/find")
    public ResponseEntity<InformationDTO> selectInfo(){
        InformationDTO informationDTO = informationService.selectInfoByUserId();
        return ResponseEntity.ok(informationDTO);
    }


    /**
     * 省级联动
     * @param id 传入当前请求的id
     * @return 查询相应数据表的集合
     */
    @GetMapping("/location/{id}")
    public ResponseEntity<List<LoDTO>> selectLocation(@PathVariable String id){
        List<LoDTO> listLoDTO = informationService.findAllById(id);
        return ResponseEntity.ok(listLoDTO);
    }
}
